package com.weblog.spider.task;

import com.weblog.spider.pipeline.ArticlePipline;
import com.weblog.spider.processor.ArticleProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.scheduler.QueueScheduler;
import us.codecraft.webmagic.scheduler.RedisScheduler;

/**
 * @author MaoLin Wang
 * @date 2019/11/2421:19
 */
@Component
public class ArticleTask {

    @Autowired
    private ArticleProcessor articleProcessor;
    @Autowired
    private ArticlePipline articlePipline;
    @Autowired
    private RedisScheduler redisScheduler;

    @Scheduled(cron = "0 52 23 * * ?")
    public void javaTask(){
        System.out.println("爬取java分类文章");
        Spider spider=Spider.create(articleProcessor);
         spider.addUrl("https://www.cnblogs.com/cate/java/")
                .addPipeline(articlePipline)
                .start();
    }
}
